﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xenta.Operations;
using Xenta.Utils;

namespace Xenta.Tests.Operations
{
    [TestFixture]
    public class FileFolderTranslationTests : OperationTest
    {
        protected override IEnumerable<Type> ModelMappings
        {
            get
            {
                return NHMappings.ALL;
            }
        }

        [TestCase("name")]
        public void Can_CRUD(string name)
        {
            var t_folder = Processor.Execute(new CreateFileFolderTranslation
            {
                HolderID = Processor.Execute(new CreateFileFolder
                {
                    ParentID = 0
                }).Result.EntityID,
                LanguageID = Processor.Execute(new CreateLanguage
                {
                    Code = "xy"
                }).Result.EntityID,
                Name = name
            }).Result;

            Assert.NotNull(t_folder);
            t_folder.Name.AreEqualIgnoringCase(name);
            t_folder.AreEqual(Processor.Execute(new GetFileFolderTranslation
            {
                EntityID = t_folder.EntityID
            }).Result);

            name = name.Reverse();
            var upd_t_folder = Processor.Execute(new UpdateFileFolderTranslation
            {
                EntityID = t_folder.EntityID,
                LanguageID = t_folder.Language.EntityID,
                Name = name
            }).Result;

            Assert.NotNull(upd_t_folder);
            upd_t_folder.AreEqual(t_folder);
            upd_t_folder.Name.AreEqualIgnoringCase(name);

            Processor.Execute(new DeleteFileFolderTranslation
            {
                EntityID = t_folder.EntityID
            });
        }
    }
}
